#import "SEGUserinsertuserManager.h"

#if __has_include(<Commom/SEGModel.h>)
#import <Commom/SEGModel.h>
#else
#import "SEGModel.h"
#endif
#if __has_include(<Commom/SEGHTTPBusinessManager.h>)
#import <Commom/SEGHTTPBusinessManager.h>
#else
#import "SEGHTTPBusinessManager.h"
#endif

static id _UserInsertUserManager;
static dispatch_once_t onceToken;

@implementation SEGUserinsertuserManager
#pragma mark - SINGLE----BEGIN----
+(instancetype)sharedManager{
    dispatch_once(&onceToken, ^{
        _UserInsertUserManager = [[self alloc] init];
    });
    return _UserInsertUserManager;
}

+(void)destroyResource{
    onceToken = 0;
    _UserInsertUserManager = nil;
}

#pragma mark - SINGLE----END----

#pragma mark - HTTP----BEGIN----
//"userType":1                //类型：Number  必有字段  备注：用户类型：1管理员，2普通员工
-(void)requestUserinsertuserWithCustname:(NSString*)custName userTel:(NSString*)userTel enterpriseId:(NSString*)enterpriseId roleId:(NSString*)roleId communityId:(NSString*)communityId propId:(NSString*)propId userType:(NSString*)userType finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:custName forKey:@"custName"];
    [params setValue:userTel forKey:@"userTel"];
    [params setValue:enterpriseId forKey:@"enterpriseId"];
    [params setValue:roleId forKey:@"roleId"];
    [params setValue:communityId forKey:@"communityId"];
    [params setValue:propId forKey:@"propId"];
    [params setValue:userType forKey:@"userType"];
    
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/enterprise-app/user/insertCommonUser",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        self.UserInsertUser = [SEGUserinsertuserModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}

-(void)requestUpdateUserCommonWithUserCustRelIds:(NSString*)userCustRelIds roleId:(NSString*)roleId userName:(NSString*)userName finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:userCustRelIds forKey:@"enterpriseUserId"];
    [params setValue:roleId forKey:@"roleId"];
    [params setValue:userName forKey:@"userName"];
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/enterprise-app/user/updateUserCommon",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        self.UserInsertUser = [SEGUserinsertuserModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}

/*
 删除员工
 */
-(void)requestDeleteUserWithUserCustRelIds:(NSString*)userCustRelIds finished:(void(^)(BOOL isSuccessed,id result,NSString* codeType,NSString* errorMessage))finished{
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    [params setValue:userCustRelIds forKey:@"enterpriseUserId"];
    NSString *urlString = [SEGServerManager serverUrlJoint:kClientRootURL,@"/enterprise-app/user/deleteUser",nil];
    [SEGHTTPBusinessManager seg_requestJSONWithMethod:POST URLString:urlString parameters:params completed:^(BOOL isSuccessed, id result, NSString *codeType, NSError *error) {
        if (!isSuccessed) {
            finished(isSuccessed,nil,codeType,error.localizedDescription);
            return;
        }
        self.UserInsertUser = [SEGUserinsertuserModel yy_modelWithDictionary:result];
        finished(isSuccessed,result,codeType,error.localizedDescription);
        return;
    }];
}
#pragma mark - HTTP----END----

#pragma mark - GETTER----BEGIN----
-(SEGUserinsertuserModel *)UserInsertUser{
    if (!_UserInsertUser) {
        _UserInsertUser = [[SEGUserinsertuserModel alloc]init];
    }
    return _UserInsertUser;
}
#pragma mark - GETTER----END----
@end

